package com.zyz.O_网络编程.TCP.聊天室;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/**
 * @author: vick
 * @Date: 2025/4/17
 * @Description:
 * @version: 1.0
 */
public class TcpChatServer {

    //存储所有在线的客户端
    private static ArrayList<Socket> online = new ArrayList<>();
    public static void main(String[] args) throws IOException {
         //1. 创建ServerSocket对象，绑定8888端口
        ServerSocket serverSocket = new ServerSocket(8888);

        //接收多个客户端同时连接
        while (true) {
            //2. 监听客户端的连接
            Socket socket = serverSocket.accept();
            online.add(socket);

            MessageHandle messageHandle = new MessageHandle(socket, online);
            messageHandle.start();
        }
    }
}
